package org.yoki.edu.common.protocol.radius.msg.packet.check.resp;

import org.yoki.edu.common.protocol.radius.attribute.attr.check.*;
import org.yoki.edu.common.protocol.radius.msg.packet.RadiusMsg;
import org.yoki.edu.common.protocol.radius.msg.packet.RespRadiusMsg;

/**
 * @author Sky$
 * @Description: TODO
 * @date 2018/1/12$ 9:33$
 */
public class AccessChallengeMsg extends RespRadiusMsg {

    public static final int PACKET_CODE = 11;

    public AccessChallengeMsg(String secret, RadiusMsg reqMsg) {
        super(secret, reqMsg);
        code = getPacketCode() ;
    }

    @Override
    public int getPacketCode() {
        return PACKET_CODE;
    }

    @Override
    protected boolean typeLegal(int type , boolean print) {
        if ((type != ReplyMessageAttr.ATTR_TYPE) && (type != StateAttr.ATTR_TYPE)
                && (type != VendorSpecificAttr.ATTR_TYPE) && (type != SessionTimeoutAttr.ATTR_TYPE)
                && (type != IdleTimeoutAttr.ATTR_TYPE) && (type != ProxyStateAttr.ATTR_TYPE)) {
            if(print) {
                System.out.println("Data can not be converted into this type of attribution , Type is inconsistent !!! " +
                        "Radius Access-Challenge packet required type must be [ "
                        + ReplyMessageAttr.ATTR_TYPE + " , " + StateAttr.ATTR_TYPE + " , "
                        + VendorSpecificAttr.ATTR_TYPE + " , " + SessionTimeoutAttr.ATTR_TYPE + " , "
                        + IdleTimeoutAttr.ATTR_TYPE + " , " + ProxyStateAttr.ATTR_TYPE
                        + " ]");
            }
            return false;
        }
        return true;
    }
}
